package zhupf.test.designPattern.factory.simpleFactory.pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OrderPizza {

    SimpleFactory simpleFactory;

//    public OrderPizza(){
//        Pizza pizza = null;
//
//        String orderType; // 订购披萨的类型
//
//        do{
//            orderType = getType();
//            if(orderType.equals("greek")){
//                pizza = new GreekPizza();
//                pizza.setName("希腊披萨");
//            }else if (orderType.equals("cheese")){
//                pizza = new CheesePizza();
//                pizza.setName("奶酪披萨");
//            }else {
//                break;
//            }
//
//            pizza.preper();
//            pizza.bake();
//            pizza.cut();
//            pizza.box();
//
//        }while(true);
//    }
    public OrderPizza(SimpleFactory simpleFactory){
        this.simpleFactory = simpleFactory;

        do {
            Pizza pizza = SimpleFactory.getPizza(getType());
            if (pizza != null){
                pizza.preper();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
                break;
            }
        }while(true);
    }


    private String getType(){
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

}
